package com.education.myproject.ui.main;

import com.education.myproject.App;
import com.education.myproject.bean.DouyuBean;
import com.education.myproject.bean.RoomBean;

import java.util.List;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Subscriber;

/**
 * Created by zhonghang on 2016/10/4.
 */

public class MainPresenter implements MainContract.Presenter {
    private MainContract.Modle modle;
    private MainContract.View view;
    @Override
    public void getVerticalFromNet(Map<String, String> params) {

        modle.getVertical(params, new Subscriber<DouyuBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                view.onVerticalFail(""+e.getMessage());
            }

            @Override
            public void onNext(DouyuBean douyuBean) {
                List<RoomBean> rooms=douyuBean.getData();
                App.getLiteOrm().insert(rooms);
                view.onVerticalSucess(douyuBean.getData());
            }
        });
    }


    @Override
    public void getVerticalFromDb() {
        modle.getVerticalFromDb(new Subscriber<List<RoomBean>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(List<RoomBean> roomBeanList) {
                view.onVerticalSucess(roomBeanList);
            }
        });
    }
}
